package ch11_多线程与并发;

public class YieldDemo {
	class Counter extends Thread {
		boolean b;

		Counter(boolean b) {
			this.b = b;
		}

		public void run() {
			int i = 1;
			while (i <= 12) {
				System.out.printf("%-3s", b ? i : "^");
				if (b && i % 7 == 0) {
					Thread.yield();
				}
				i++;
			}
		}
	}

	public static void main(String[] args) {
		YieldDemo demo = new YieldDemo();
		Counter c1 = demo.new Counter(true);
		Counter c2 = demo.new Counter(false);
		c1.start();
		c2.start();
	}
}
